﻿@model Wheeler.Web.ViewModels.VehicleViewModel
@using Wheeler.Web.Utility;

@{
	String pageTitle = "Edit Registration Information";
    if (Model != null && Model.ID == 0)
    {
        pageTitle = "Register a new Auto Rickshaw";
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    if (UserInfo.IsAdmin) {
        ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = AdminMenu.EditVehicle;
    }
    else {
        ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = OperatorMenu.Vehicles;
    }
	bool _HasSaved = ViewData.HasSaved();
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>Enter necessary information and then click the Save button.</div>
</div>
<div class="jb-page-content">
@using (Html.BeginForm()) {
    @Html.ValidationSummary(false)

	if (Model == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested Auto Rickshaw was not found for edit.")
    }
    else if(Model.ID > 0 && !UserInfo.CanEditVehicleInfo(Model.HasPublished)){        
        @: @Html.WarningMessageBox("Sorry! Requested Auto Rickshaw information cannot be edited, because its Data Sheet has been submitted.", "Access Denied!")       
    }
    else
    {
        if (_HasSaved) {
            @*if (UserInfo.CanEditVehicleInfo(Model.HasPublished) && Model.HasPublished) {
                @Html.SuccessMessageBox("Congratulations! The Auto Rickshaw registered successfully. <ul><li><a class='btn btn-mini' href='/Private/TestResult/Edit?VehicleID=" + Model.ID + "'>Edit Data Sheet</a> of this Auto Rickshaw.</li> <li><a class='btn btn-mini' href='/Private/Vehicle/Edit'>Register</a> another Auto Rickshaw.</li></ul>")
            }
            else if(!UserInfo.CanEditVehicleInfo(Model.HasPublished) && Model.HasPublished){
               @Html.SuccessMessageBox("Congratulations! The Auto Rickshaw registered successfully. <ul> <li><a class='btn btn-mini' href='/Private/Vehicle/Edit'>Register</a> another Auto Rickshaw.</li></ul>") 
            }
            else {                
                @Html.SuccessMessageBox("Congratulations! The Auto Rickshaw registered successfully. <ul><li>Enter <a class='btn btn-mini' href='/Private/TestResult/Edit?VehicleID=" + Model.ID + "'>Data Sheet</a> for this Auto Rickshaw.</li> <li><a class='btn btn-mini' href='/Private/Vehicle/Edit'>Register</a> another Auto Rickshaw.</li></ul>")
            }*@
            @Html.SuccessMessageBox("Congratulations! The Auto Rickshaw registered successfully. <ul><li>Enter <a class='btn btn-mini' href='/Private/TestResult/Edit?VehicleID=" + Model.ID + "'>Data Sheet</a> for this Auto Rickshaw.</li> <li><a class='btn btn-mini' href='/Private/Vehicle/Edit'>Register</a> another Auto Rickshaw.</li></ul>")
        }
        else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved)
        {
            @Html.WarningMessageBox("Sorry! we could not register the Auto Rickshaw.")
        }

        if (UserInfo.CanEditVehicleInfo(Model.HasPublished) && Model.HasPublished)
        {
            @: @Html.WarningMessageBox("Warning! Data Sheet of this Auto Rickshaw has already been submitted. <br/>Are you sure you want to edit the information?", String.Empty)
        }
		@Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.FixedVehicleID)
        
        <div class="editor-label">
			@Html.LabelFor(model => model.BRTANumber)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.BRTANumber)
			@Html.ValidationMessageFor(model => model.BRTANumber)
		</div>
    
        <div class="jb-group-title">Auto Rickshaw Information</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.RegistrationNo)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.RegistrationNo)
			@Html.ValidationMessageFor(model => model.RegistrationNo)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.EngineNo)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.EngineNo)
			@Html.ValidationMessageFor(model => model.EngineNo)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.ChasisNo)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.ChasisNo)
			@Html.ValidationMessageFor(model => model.ChasisNo)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.CNGCylinderNo)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.CNGCylinderNo)
			@Html.ValidationMessageFor(model => model.CNGCylinderNo)
		</div>
    
        <div class="jb-group-title">Owner Information</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.RegistrationDate)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.RegistrationDate, new { @class = "datepicker" })
			@Html.ValidationMessageFor(model => model.RegistrationDate)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.OwnerName)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.OwnerName)
			@Html.ValidationMessageFor(model => model.OwnerName)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Address)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.Address)
			@Html.ValidationMessageFor(model => model.Address)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.CellPhone)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.CellPhone)
			@Html.ValidationMessageFor(model => model.CellPhone)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.FormSubmissionDate)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.FormSubmissionDate, new { @class = "datepicker" })
			@Html.ValidationMessageFor(model => model.FormSubmissionDate)
		</div>
		
        @Html.HiddenFor(model => model.IsVerified)
		@Html.HiddenFor(model => model.CreatedOn)
		@Html.HiddenFor(model => model.ModifiedOn)
		@Html.HiddenFor(model => model.ModifiedBy)
        @Html.HiddenFor(model => model.CreatedBy)
        @Html.HiddenFor(model => model.PictureFile)
		<div class="jb-button-container">
			<button class="btn btn-primary" type="submit" data-loading-text="Saving..."><i class="icon-hdd icon-white"></i> Save</button> 
			<a class="btn" href="/Private/Vehicle/Search"><i class="icon-arrow-left"></i> Go Back</a>
		</div>		
    }
}
</div>

@section PageHeadSection
{
    <link href="@Url.Content("~/Content/themes/jb-ui/jquery.ui.all.css")" rel="stylesheet" type="text/css" />    
}

@section JavaScriptPlaceHolder
{
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
@Html.JavaScript("jquery-ui-1.8.11.min.js", Url)
@Html.Partial("_DatePicker")
}

